vcpkg_download_distfile(
    CALLBACK_PATCH
    URLS https://github.com/esnet/iperf/commit/5a5957f63f8e053049f764bd05792992c94922ba.patch
    SHA512 526e7e48f067152ef7d5355cd494559824216ad46e71b3c73eb14d7a1c04ff6629fdbe8d7bed3f78ff9d0b4eedaa6849b30c469dc82caae97f748c39d0112810
    FILENAME 5a5957f63f8e053049f764bd05792992c94922ba.patch
)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO esnet/iperf
    REF "${VERSION}"
    SHA512 468bbb040e8dc43c664854c823b7d79d9836da774a53f080fdd2258c836874247ca1f876dff490021e0ad3d38a00f972ffeea10eb149fb1fc75bf18e8fd9e974
    HEAD_REF master
    PATCHES
        ${CALLBACK_PATCH}
)

vcpkg_configure_make(
    SOURCE_PATH ${SOURCE_PATH}
    AUTOCONFIG
    CONFIGURE_ENVIRONMENT "CFLAGS=-fPIC" # 确保生成的库支持动态链接
    OPTIONS
        "--with-openssl=no"

)

vcpkg_install_make()

vcpkg_fixup_pkgconfig()

vcpkg_copy_pdbs()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

set(IPERF_INCLUDE_DIR ${CURRENT_PACKAGES_DIR}/include)
set(IPERF_LIB_DIR ${CURRENT_PACKAGES_DIR}/lib)

file(WRITE ${CURRENT_PACKAGES_DIR}/share/iperf/iperfConfig.cmake
"set(IPERF_INCLUDE_DIR \"${IPERF_INCLUDE_DIR}\")
set(IPERF_LIB_DIR \"${IPERF_LIB_DIR}\")
include_directories(\${IPERF_INCLUDE_DIR})
link_directories(\${IPERF_LIB_DIR})
find_package(OpenSSL REQUIRED)
"
)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")